import { defineStore } from 'pinia'

const useDictStore = defineStore('dict', {
  state: () => {
    return {
      dictMap: new Map()
    }
  },
  actions: {
    // 获取字典
    getDict(key) {
      if(key === null || key === '') {
        return null;
      }
      return this.dictMap.get(key);
    },
    // 设置字典
    setDict(key, value) {
      if(key !== null && key !== '' && value !== null){
        this.dictMap.set(key, value)
      }
    },
    // 清除指定字典缓存
    removeDict(key) {
      this.dictMap.delete(key);
    },
    // 清除所有字典缓存
    clearDict() {
      this.dictMap.clear();
    }
  }
}) 
export default useDictStore;